import request from '@/utils/request'

export interface DictTable {
  tableName: string
  tableComment?: string
  enabled?: number
  remark?: string
}

export interface DictField {
  tableName: string
  columnName: string
  columnType?: string
  dataType?: string
  columnComment?: string
  required?: number
  uniqueFlag?: number
  visible?: number
  dictType?: string
  label?: string
  sort?: number
  remark?: string
}

export const dictionaryApi = {
  getTables(params?: { tableName?: string; comment?: string }) {
    return request.get('/api/system/dictionary/tables', params)
  },
  getColumns(tableName: string, params?: { columnName?: string }) {
    return request.get(`/api/system/dictionary/tables/${tableName}/columns`, params)
  },
  saveFields(data: DictField[]) {
    return request.post('/api/system/dictionary/fields/batch-save', data)
  },
  /**
   * 创建业务表
   */
  createTable(tableName: string, columns: any[], comment?: string) {
    return request.post(`/api/system/dictionary/tables/${tableName}`, columns, { params: { comment } })
  },
  /**
   * 为现有表新增字段
   */
  addColumns(tableName: string, columns: any[]) {
    return request.post(`/api/system/dictionary/tables/${tableName}/columns`, columns)
  }
}

export default dictionaryApi


